package com.yeqian.article.controller;

import com.github.pagehelper.PageInfo;
import com.yeqian.article.entity.Comment;
import com.yeqian.vo.PageVO;
import com.yeqian.article.service.CommentService;
import com.yeqian.entity.ResultJson;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 评论控制器
 */
@Slf4j
@RestController
@RequestMapping(Urls.CommentInfo.COMMENT)
public class CommentController {


    @Resource
    private CommentService commentService;

    /**
     * 获取评论树
     *
     * @return
     */
    @PostMapping(Urls.CommentInfo.TREE_COMMENT)
    public ResultJson treeComment(@RequestBody PageVO pageVO) {
        PageInfo<Map<String, Object>> list = commentService.treeComment(pageVO);
        return ResultJson.Success("查看评论树列表成功", list);
    }

    /**
     * 新增评论
     *
     * @param comment
     * @return
     */
    @PostMapping(Urls.CommentInfo.SAVE_COMMENT)
    public ResultJson saveComment(@RequestBody Comment comment) {
        commentService.saveComment(comment);
        return ResultJson.Success("新增评论成功");
    }

    /**
     * 删除评论 对应表主键（多个以,分割）,将父评论及子评论的id用id分割
     *
     * @param
     * @return
     */
    @PostMapping(Urls.CommentInfo.DELETE_COMMENT)
    public ResultJson deleteComment(String ids) {
        commentService.deleteComment(ids);
        return ResultJson.Success("删除评论成功");
    }
}
